import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-09-09
 * Time: 21:59
 */
public class test {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch downLatch = new CountDownLatch(8);   //大任务划分成8个小任务让8个线程去执行
        for(int i = 0; i < 8; i++){
            final int id = i;
            Thread t = new Thread(()->{
                System.out.println("运动员" + id + "开始");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("运动员" + id + "到达终点");
                downLatch.countDown(); //撞线操作, 线程任务完成
            });
            t.start();
        }
        downLatch.await();
        System.out.println("比赛结束");
    }
}
